﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using FluentNHibernate.Conventions;
using FluentNHibernate.Conventions.Instances;

namespace Domain.Model.Mapping.Conventions
{
    /// <summary>
    /// This class is used to define, how table names should be 
    /// generated, depending on the name of the Entity.
    /// </summary>
    public class TableNameConvention : IClassConvention
    {
        public void Apply(IClassInstance instance)
        {
            string tableName = instance.EntityType.Name;

            if (tableName.EndsWith("y"))
            {
                tableName = tableName.Substring(0, tableName.Length - 1);
                tableName += "ies";
            }
            else if (tableName.EndsWith("s"))
            { 
            
            }
            else
            {
                tableName += "s";
            }

            instance.Table(tableName);
        }
    }
}